cmake_minimum_required(VERSION 3.8)
project(hudar_core)

option(CUDA_USE_STATIC_CUDA_RUNTIME OFF)
add_compile_options(-std=c++17)

set(CUDA_GEN_CODE "-gencode=arch=compute_75,code=sm_75")
set(CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS}  -std=c++17 -O3 -Xcompiler -fPIC -g -w ${CUDA_GEN_CODE}")

if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
  
endif()

# find dependencies
find_package(CUDA REQUIRED)
find_package(ament_cmake REQUIRED)
find_package(rclcpp REQUIRED)
find_package(sensor_msgs REQUIRED)
find_package(OpenCV 4 REQUIRED)
find_package(cv_bridge REQUIRED)
find_package(hudar_msg REQUIRED)   
if(BUILD_TESTING)
  find_package(ament_lint_auto REQUIRED)
  # the following line skips the linter which checks for copyrights
  # comment the line when a copyright and license is added to all source files
  set(ament_cmake_copyright_FOUND TRUE)
  # the following line skips cpplint (only works in a git repo)
  # comment the line when this package is in a git repo and when
  # a copyright and license is added to all source files
  set(ament_cmake_cpplint_FOUND TRUE)
  ament_lint_auto_find_test_dependencies()
endif()


include_directories(${EIGEN3_INCLUDE_DIRS})

# cuda
include_directories(/usr/local/cuda/include)
link_directories(/usr/local/cuda/lib64)
# cudnn
include_directories(/data/cuda/cuda-11.8/cudnn/v8.0.4/include)
link_directories(/data/cuda/cuda-11.8/cudnn/v8.0.4/lib64)

include_directories(/usr/local/TensorRT-10.0.1.6/include)
link_directories(/usr/local/TensorRT-10.0.1.6/lib)






cuda_add_executable(radar_front src/radar_front.cpp src/Detectors/Detector.cpp 
src/TRTGenerator/TRTGenerator/src/Generator.cpp
src/TRTInference/TRTInfer/src/Inference.cpp
src/TRTInference/TRTInfer/CUDA/preprocess.cu
)
add_executable(radar_mapping src/radar_mapping.cpp)
ament_target_dependencies(radar_front rclcpp OpenCV std_msgs sensor_msgs cv_bridge hudar_msg)
ament_target_dependencies(radar_mapping rclcpp OpenCV std_msgs hudar_msg)

set_target_properties(radar_front PROPERTIES CUDA_SEPARABLE_COMPILATION ON)
target_link_libraries(radar_front nvinfer)
target_link_libraries(radar_front cudart)
target_link_libraries(radar_front nvonnxparser)
target_link_libraries(radar_front ${Eigen3_LIBRARIES})


add_definitions(-O3 -pthread)

install(TARGETS
  radar_front
  radar_mapping
  DESTINATION lib/${PROJECT_NAME}
)

ament_package()

macro(remove_warnings)
  add_definitions(-Wno-deprecated-declarations
    -Wno-unused-but-set-variable
    -Wno-unused-variable)
endmacro()

remove_warnings()
